package com.ls.fw.remoting.dubbo.service.impl;

import java.io.FileInputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.alibaba.dubbo.rpc.RpcContext;
import com.ls.fw.remoting.dubbo.service.DemoService;

public class DemoServiceImpl implements DemoService{  
    
	@Override  
    public String sayHello(String name) {  
		  System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
	      return "Hello " + name + ", response form provider: " + RpcContext.getContext().getLocalAddress();
	}
	
	@Override  
    public InputStream download(String path) {  
        System.out.println(path+"******************************");  
        try {  
            InputStream inputStream = new FileInputStream(path);  
            return inputStream;  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return null;  
    }  
    
	
    @Override  
    public String upload(String destPath,InputStream in) {  
        try {  
            //FileOutputStream out = new FileOutputStream("E:\\temp\\a.js");  
            int n = -1;  
            byte[] b = new byte[10240];  
            while((n=in.read(b)) != -1){  
                System.out.println(new String(b,0,n,"utf-8"));  
                //out.write(b, 0, n);  
            }  
            //out.close();  
            //out.flush();  
            in.close();  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return "upload complete !";  
    }  
}  